﻿

import Request from '../../base/request.js?t=202511041006'
import Storage from '../../base/storage.js?t=202511041006'
import { dealTime, queryURLParams, getRecentYears, getMonthList, getBrowserInfo, popShowCom } from "../../base/utils.js?t=202511041006"
const Composition = (proxy) => {

 
    


    const data = reactive({
        messageTest: "",
        proxy: "",
        popTitle: "",
        cIndex: 1,
        tabList: [
            {
                label: '公司级', value: 1
            }, {
                label: '部门级', value: 2
            }],
        queryParams: {
            Title: null,
            Time: null,
            Status:null
        },
        urlinfo: {},
        userinfo: {},
        statusList: [
            {
                label: '保存', value: 0
            },
            {
                label: '发布', value: 1
            }
        ],
        opType: true,
        popShow: false,
        pagination: {
            total: 0,
            current: 1,
            pageSize: 10,
            loading: true,
            showTotal: total => `总共 ${total} 项`,
            defaultPageSize: 10,
            showSizeChanger: true, // 是否显示pagesize选择
            showQuickJumper: false, // 是否显示跳转窗
        },

        yearList: [

        ],
        monthList: [
        ],

        columns: [
            {
                title: '序号',
                dataIndex: 'index',
                key: 'index',
                align: 'center',
                width: 80,
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },
            {
                title: '年度',
                dataIndex: 'PushlishYear',
                key: 'PushlishYear',
                align: 'center'

            },
            {
                title: '标题',
                dataIndex: 'Title',
                key: 'Title',
                align: 'center'

            },

            {
                title: '部门',
                dataIndex: 'DepNameList',
                key: 'DepNameList',
                align: 'center',
                customRender: function ({ text }) {
                    return popShowCom(text)
                }
            },
            {
                title: '发布日期',
                dataIndex: 'UpdateTime',
                key: 'UpdateTime',
                align: 'center',
                customRender: function ({ text }) {
                    return dealTime(text, 'YYYY-MM-DD HH:mm')
                }

            },
            {
                title: '状态',
                dataIndex: 'StatusName',
                key: 'StatusName',
                align: 'center',
                customRender: function ({ text, record }) {
                    let steps = h(antd.Steps, {
                        type: "inline",
                        current: params.statusList.value.findIndex((e) => {
                            return e.label == record.StatusName
                        }),
                        items: params.statusList.value.map(e => {
                            return {
                                key: e.label,
                                title: e.label,
                                description: e.label
                            }
                        }),
                    }, { default: () => text });
                    let textc = h(antd.Tag, {
                        color: "#2178e9",
                        style: 'cursor:pointer'
                    }, { default: () => text });

                    return h(antd.Popover, {
                        title: '当前节点',
                        content: steps,
                    }, () => [textc]);

                }

            },
            {
                title: '操作',
                key: 'action',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    const FDBtn = h(antd.Popconfirm, {
                        title: `提示：标题【${record.Title}】，删除后将无法恢复，请您确认。`,
                        onConfirm: () => methods.handleDelete(record)

                    }, { default: () => [delBtn] })
                    let returnBtn = h(antd.Button, {
                        type: "link",
           
                    }, { default: () => '撤回' })
                    const FWBtn = h(antd.Popconfirm, {
                        title: "确定撤回?",
                        onConfirm: () => methods.handleReturn(record)

                    }, { default: () => [returnBtn] })


       


                    let detailBtn = h(antd.Button, {
                        type: "link",
                        onClick: () => {
                            methods.handleDetail(record)
                        }
                    }, { default: () => '详情' })

                    let editBtn = h(antd.Button, {
                        type: "link",
                        onClick: () => {
                            methods.handleEdit(record)
                        }
                    }, { default: () => '编辑' })

                    let uploadBtn = h(antd.Button, {
                        type: "link",
                        onClick: () => {
                            methods.handleReview(record)
                        }
                    }, { default: () => '操作' })

                    //let reviewBtn = h(antd.Button, {
                    //    type: "link",
                    //    onClick: () => {
                    //        methods.handleReview(record)
                    //    }
                    //}, { default: () => '复查' })

                    //let nreviewBtn = h(antd.Button, {
                    //    type: "link",
                    //    onClick: () => {
                    //        methods.handleReview(record,true)
                    //    }
                    //}, { default: () => '复查情况' })

                    let delBtn = h(antd.Button, {
                        type: "link",
                        danger:true

                    }, { default: () => '删除' })

                    return h('div', {
                    },
                        { default: () => [record.IsShowUpload ? uploadBtn : null, record.IsEdit ? editBtn : null, record.IsDelete ? FDBtn : null, record. IsCallback ?  FWBtn:null, detailBtn] }
                    );

                }
            },
        ],
        dataSource: [],
    })
    let params = toRefs(data)
    const methods = {
        tchange: (e) => {
            methods.getTableList(true)
            params.queryParams.value = {

            }
        },
        toAdd: (target) => {
            window.open(`/EmergencyManagement/EDADD`, "_self")
        },
        //handleUpload: (item) => {
        //    window.open(`/EmergencyManagement/EDADD?target=1&id=${item.Id}`, "_self")
        //},
        handleReview: (item, flag) => {
            if (!flag) {
                window.open(`/EmergencyManagement/EDADD?target=2&id=${item.Id}`, "_self")
            } else {
                window.open(`/EmergencyManagement/EDADD?target=2&id=${item.Id}&d=1`, "_self")
            }
        },
        handleOk: () => {
            params.popShow.value = false
        },
        handleDetail: (item) => {
            window.location.href = `/EmergencyManagement/EDADD?id=${item.Id}&type=9`
        },
        handleEdit: (item) => {
            window.location.href = `/EmergencyManagement/EDADD?id=${item.Id}&type=1`
        },
        handleDelete: (item) => {
            Request({
                url: "/EmergencyPlan/DeleteEmergencyDrillPlan",
                method: 'post',
                data: {
                    Id: item.Id
                }
            }).then(res => {
                params.messageTest.value.success(res.Msg);
                methods.getTableList(true)
            })
        },
        handleReturn: (item) => {
            Request({
                url: "/EmergencyPlan/CallbackDrillPlan",
                method: 'post',
                data: {
                    Id: item.Id
                }
            }).then(res => {
                params.messageTest.value.success(res.Msg);
                methods.getTableList(true)
            })
        },
        filterOption: (val, type) => {
            return `${type.label}`.includes(`${val || ''}`)
        },
        handleTableChange: (page) => {
            const { current, pageSize } = page
            params.pagination.value.current = current;
            params.pagination.value.pageSize = pageSize;
            methods.getTableList()
        },
        handleReset: () => {
            params.queryParams.value= {
                Title: null,
                    Time: null,
                        Status: null
            }
            methods.getTableList(true)
        },
        getTableList: async (isRresh) => {
            if (isRresh) {
                params.pagination.value.current = 1
            }
            params.pagination.value.loading = true
            Request({
                url: "/EmergencyPlan/GetEmergencyDrillPlanPageList",
                method: 'post',
                params: {
                    page: params.pagination.value.current,
                    pageSize: params.pagination.value.pageSize
                },
                data: {
                    model: {
                        Title: params.queryParams.value.Title,
                        StartTime: params.queryParams.value.Time && dayjs(params.queryParams.value.Time[0]).format('YYYY'),
                        EndTime: params.queryParams.value.Time && dayjs(params.queryParams.value.Time[1]).format('YYYY'),
                        Status: params.queryParams.value.Status,
                    }

                }
            }).then(res => {
                params.dataSource.value = res.Data.Data
                params.pagination.value.total = res.Data?.TotalItemCount
                params.pagination.value.loading = false
            })

        },


        init: () => {

            getBrowserInfo().catch(err => { console.log(err) })
            if (proxy) {
                params.proxy.value = proxy
            }
            params.urlinfo.value = queryURLParams()
            params.yearList.value = getRecentYears()
            params.monthList.value = getMonthList()
            const { message } = antd
            params.messageTest.value = message
            params.messageTest.value.config({
                top: `10vh`,
                duration: 7,
                maxCount: 1,
                rtl: true,
            });

            setTimeout(() => {
                let info = Storage.get('AccountInfo', true)
                params.userinfo.value=info

                Request({
                    url: "/Account/createJwtToken",
                    method: 'post',
                    data: {
                        "userName": info && info.UserNo
                    }
                }).then(async res => {
                    Storage.set('token', res.Data,true)

                    methods.getTableList(true)
                })
            }, 400)

        },

    }



    const template = {
        test: {
            template: `<div @click="add">+</div> <div>{{testnum}}</div>`,

            setup() {

                return {
                    ...params,
                    ...methods,
                };
            }

        }
    }
    return {
        ...params,
        ...methods,
        template
    }
}

export default Composition